<template>
  <el-dialog title="通知" :model-value="modelValue" @close="closed" width="22%">
    <div class="content">
      <p class="title">切换主题</p>
      <el-color-picker v-model="myColor" :predefine="predefineColors"></el-color-picker>
    </div>
    <template #footer>
      <el-button @click="closed">取消</el-button>
      <el-button type="primary" @click="confirm">确认</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { useStore } from 'vuex'
import { defineProps, defineEmits, ref } from 'vue'
defineProps({
  modelValue: {
    type: Boolean,
    required: true
  }
})

const store = useStore()
const emits = defineEmits(['update:modelValue'])
// 预定义色值
const predefineColors = [
  '#ff4500',
  '#ff8c00',
  '#ffd700',
  '#90ee90',
  '#00ced1',
  '#1e90ff',
  '#c71585',
  'rgba(255, 69, 0, 0.68)',
  'rgb(255, 120, 0)',
  'hsv(51, 100, 98)',
  'hsva(120, 40,, 94, 0.5)',
  'hsl(181, 100%, 37%)',
  'hsla(209, 100%, 56%, 0.73)',
  '#c7158577'
]
// 默认色值设置
const myColor = ref(store.getters.mainColor)
const closed = () => {
  emits('update:modelValue', false)
}

/**
 * 确定按钮点击事件
 */
const confirm = () => {
  store.commit('theme/setMainColor', myColor.value)
  closed()
}
</script>

<style lang="scss" scoped>
.content {
  text-align: center;
  .title {
    margin-bottom: 10px;
  }
}
</style>
